package com.candy.security.jwt.util;

import com.candy.security.jwt.entity.LoginUser;
import com.candy.security.jwt.service.IAuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 安全服务工具类
 */
@Component
public class SecurityUtils
{
    @Autowired
    IAuthenticationService authenticationService;

    private static IAuthenticationService StaticAuthenticationService;

    @PostConstruct
    void init()
    {
        StaticAuthenticationService = authenticationService;
    }

    /**
     * 获取用户账户
     **/
    public static String getLoginName()
    {
        return StaticAuthenticationService.getLoginName();
    }

    /**
     * 获取用户
     **/
    public static LoginUser getLoginUser()
    {
        return StaticAuthenticationService.getLoginUser();
    }

    /**
     * 是否为管理员
     * 
     * @param userId 用户ID
     * @return 结果
     */
    public static boolean isAdmin(Long userId)
    {
        return StaticAuthenticationService.isAdmin(userId);
    }
}
